const requestApi = "http://192.168.1.174:5126/";

let requestRecord = {};


export default function({
	url,
	data,
	method = "POST"
}, callback) {
	return new Promise((reslove, reject) => {
		if (Object.hasOwnProperty.call(requestRecord, `${url}:${method}`) && requestRecord[
				`${url}:${method}`] == data) {
			reject();
		}
		requestRecord[`${url}:${method}`] = data;
		uni.request({
			url: requestApi + url,
			data,
			method,
			header: {
				'content-type': 'application/json',
				'Access-Control-Allow-Origin': "*"
			},
			success(res) {
				Reflect.deleteProperty(requestRecord, `${url}:${method}`);
				const responestData = res.data;
				if (typeof callback == "function") {
					callback(responestData, reslove);
				} else {
					if (responestData.statusCode == 200) {
						reslove({
							done: true,
							code: 0,
							data: responestData
						})
					} else {
						reslove({
							done: false,
							code: 2,
							data: responestData
						})
					}
				}
			},
			fail(res) {
				reslove({
					done: false,
					code: 3,
					data: {
						Message: "请求获取异常"
					}
				})
			},
			complete() {

			}
		})
	})
}